<?php
/**
 * Initialise l'environnement de d'exécution du script, c'est-à-dire l'environnement
 * d'exécution (développement, production , ...) et l'include path
 * 
 * @package Application_Config
 */

// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application/'));

// Define application environment
defined('APPLICATION_ENV')
|| define(
    'APPLICATION_ENV',
    (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : $_SERVER['APPLICATION_ENV']
    )
);

// Define libraries path (zend, wurfl, ...)
defined('PHP_LIBRARY_PATH')
|| define(
    'PHP_LIBRARY_PATH',
    (getenv('PHP_LIBRARY_PATH') ? getenv('PHP_LIBRARY_PATH') : $_SERVER['PHP_LIBRARY_PATH']
    )
);

// Define configuration files path
defined('PHP_CONFIGURATION_PATH')
|| define(
    'PHP_CONFIGURATION_PATH',
    (getenv('PHP_CONFIGURATION_PATH') ?
        getenv('PHP_CONFIGURATION_PATH')
        : $_SERVER['PHP_CONFIGURATION_PATH']
    )
);

// Ensure library/ is on include_path
set_include_path(
    implode(
        PATH_SEPARATOR,
        array(
            get_include_path(),
            APPLICATION_PATH,
            realpath(APPLICATION_PATH . '/../library'), // project libraries
            PHP_LIBRARY_PATH, // common libraries path
            PHP_CONFIGURATION_PATH, // common configuration files folder
        )
    )
);

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap();
